Answer:

Yes. In fact you are doing this right now. The Web page you are looking at is stored on my hard disk as a file named bc25_7.html which your computer requested when it wanted to display this page.

Writing a File

For these notes, output files will be sequential files of text. Output is done using the PRINT statement, nearly as the same way it is used when output goes to the screen. Here is a QBasic program that writes to the screen:

CLS                         ' Clear the screen
PRINT "Hello World"         ' Send characters to the screen
END                         ' End the program

The first statement CLS clear characters from the command prompt (DOS) window. You don't need to do this, but it makes it easier to see what a program has done. (Otherwise the output from previous program runs stay on the screen and make it hard to be sure what the current run has done.) The PRINT statement works like it always has and sends the characters of the string to the DOS window.

Here is nearly the same program, but now it writes the characters to a disk file:

CLS                                  ' Clear screen
OPEN "MYFILE.TXT" FOR OUTPUT AS #1   ' Open the file for output
PRINT #1, "Hello World"              ' Send characters to the file
END                                  ' End the program

The OPEN statement creates a file called MYFILE.TXT in the default directory. A file must be opened before output is done to it. If the file MYFILE.TXT already exists, the old file will be replaced with a new file. The default directory is the same as the directory that was the default for the DOS window when you started QBasic.

When you run this program (which you should do), the program prints no characters to the screen. The PRINT statement send its characters to the file.

QUESTION 8:

If the file MYFILE.TXT contained important data before you ran this program, what would happen?